using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace NorthwindDAO
{
	[Serializable]
	public class Employees_parent : Employees
	{
        public override string TableName()
        {
        	return "Employees";
        }
	}
	public class Employees_child : Employees
	{
        public override string TableName()
        {
        	return "Employees";
        }
	}
	public class Employees : Entity
	{
		private Int32 _EmployeeID;
		private String _LastName;
		private String _FirstName;
		private String _Title;
		private String _TitleOfCourtesy;
		private DateTime _BirthDate;
		private DateTime _HireDate;
		private String _Address;
		private String _City;
		private String _Region;
		private String _PostalCode;
		private String _Country;
		private String _HomePhone;
		private String _Extension;
		private Byte[] _Photo;
		private String _Notes;
		private Int32 _ReportsTo;
		private String _PhotoPath;
	
		///Default constructor
		public Employees ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available CHILD tables to join with:
		///    - Employees ( Employees_fk_employees_employees )
		///    - Employeeterritories ( Employeeterritories_fk_employeeterritories_employees )
		///    - Orders ( Orders_fk_orders_employees )
		/// Available PARENT tables to join with:
		///    - Employees
        /// </summary>
        public Employees(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_"; ;
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}
        public Employees(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		[IsNotNullable]
		[IsPK]
		[IsIdentity]
		[SequenceName("Employees")]
		public Int32 Employeeid
		{
			get
			{
				return _EmployeeID;
			}
		}
		[IsNotNullable]
		[MaxLength(20)]
		public String Lastname
		{
			get
			{
				return _LastName;
			}
			set
			{
				_LastName = value;
			}
		}
		[IsNotNullable]
		[MaxLength(10)]
		public String Firstname
		{
			get
			{
				return _FirstName;
			}
			set
			{
				_FirstName = value;
			}
		}
		[MaxLength(30)]
		public String Title
		{
			get
			{
				return _Title;
			}
			set
			{
				_Title = value;
			}
		}
		[MaxLength(25)]
		public String Titleofcourtesy
		{
			get
			{
				return _TitleOfCourtesy;
			}
			set
			{
				_TitleOfCourtesy = value;
			}
		}
		public DateTime Birthdate
		{
			get
			{
				return _BirthDate;
			}
			set
			{
				_BirthDate = value;
			}
		}
		public DateTime Hiredate
		{
			get
			{
				return _HireDate;
			}
			set
			{
				_HireDate = value;
			}
		}
		[MaxLength(60)]
		public String Address
		{
			get
			{
				return _Address;
			}
			set
			{
				_Address = value;
			}
		}
		[MaxLength(15)]
		public String City
		{
			get
			{
				return _City;
			}
			set
			{
				_City = value;
			}
		}
		[MaxLength(15)]
		public String Region
		{
			get
			{
				return _Region;
			}
			set
			{
				_Region = value;
			}
		}
		[MaxLength(10)]
		public String Postalcode
		{
			get
			{
				return _PostalCode;
			}
			set
			{
				_PostalCode = value;
			}
		}
		[MaxLength(15)]
		public String Country
		{
			get
			{
				return _Country;
			}
			set
			{
				_Country = value;
			}
		}
		[MaxLength(24)]
		public String Homephone
		{
			get
			{
				return _HomePhone;
			}
			set
			{
				_HomePhone = value;
			}
		}
		[MaxLength(4)]
		public String Extension
		{
			get
			{
				return _Extension;
			}
			set
			{
				_Extension = value;
			}
		}
		public Byte[] Photo
		{
			get
			{
				return _Photo;
			}
			set
			{
				_Photo = value;
			}
		}
		[MaxLength(16)]
		public String Notes
		{
			get
			{
				return _Notes;
			}
			set
			{
				_Notes = value;
			}
		}
		public Int32 Reportsto
		{
			get
			{
				return _ReportsTo;
			}
			set
			{
				_ReportsTo = value;
			}
		}
		[MaxLength(255)]
		public String Photopath
		{
			get
			{
				return _PhotoPath;
			}
			set
			{
				_PhotoPath = value;
			}
		}
	
        #region Employees_child 
        private EntityCollection _Employees_child;
        [NotInTable]
        [TypeContained(typeof(Employees_child),"Employees_child")]
        public EntityCollection Employees_child
        {
            get
            {
                return _Employees_child;
            }

            set
            {
                _Employees_child = value;
            }
        }
        private Employees_child _Employees_child_;
        [NotInTable]
        public Employees_child Employees_child_
        {
            get
            {
                return _Employees_child_;
            }

            set
            {
                _Employees_child_ = value;
            }
        }
        #endregion
	
        #region Employeeterritories 
        private EntityCollection _Employeeterritories;
        [NotInTable]
        [TypeContained(typeof(Employeeterritories),"Employeeterritories")]
        public EntityCollection Employeeterritories
        {
            get
            {
                return _Employeeterritories;
            }

            set
            {
                _Employeeterritories = value;
            }
        }
        private Employeeterritories _Employeeterritories_;
        [NotInTable]
        public Employeeterritories Employeeterritories_
        {
            get
            {
                return _Employeeterritories_;
            }

            set
            {
                _Employeeterritories_ = value;
            }
        }
        #endregion
	
        #region Orders 
        private EntityCollection _Orders;
        [NotInTable]
        [TypeContained(typeof(Orders),"Orders")]
        public EntityCollection Orders
        {
            get
            {
                return _Orders;
            }

            set
            {
                _Orders = value;
            }
        }
        private Orders _Orders_;
        [NotInTable]
        public Orders Orders_
        {
            get
            {
                return _Orders_;
            }

            set
            {
                _Orders_ = value;
            }
        }
        #endregion
        #region Employees 
        private EntityCollection _Employees_parent;
        [NotInTable]
        [TypeContained(typeof(Employees_parent),"Employees_parent")]
        public EntityCollection Employees_parent
        {
            get
            {
                return _Employees_parent;
            }

            set
            {
                _Employees_parent = value;
            }
        }
        private Employees_parent _Employees_parent_;
        [NotInTable]
        public Employees_parent Employees_parent_
        {
            get
            {
                return _Employees_parent_;
            }

            set
            {
                _Employees_parent_ = value;
            }
        }
        #endregion
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "Employees_child", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Reportsto");
				right.Add(GetType().Name + ".Employeeid");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "Employeeterritories", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Employeeid");
				right.Add(GetType().Name + ".Employeeid");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "Orders", true) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".Employeeid");
				right.Add(GetType().Name + ".Employeeid");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
	        if (string.Compare(tableName, "Employees", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".Employeeid");
				right.Add(GetType().Name + ".Reportsto");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			return null;
		}
	}
}


